package me.zk.practice1;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: zhang kai
 * @Date: 2022/08/28
 * @Description:
 */
public class ScheduledDemo {
    public static void main(String[] args) {
        ScheduledExecutorService schedule = Executors.newScheduledThreadPool(5);
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        System.out.println(" begin to do something at:" + sdf.format(new Date()));
        schedule.scheduleWithFixedDelay(new Job(), 1, 2, TimeUnit.SECONDS);

        //schedule.scheduleWithFixedDelay(()->System.out.println(Thread.currentThread().getName()),1,2,TimeUnit.SECONDS);
    }
}
class Job implements Runnable {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        System.out.println("do something  at:" + sdf.format(new Date()));
        System.out.println(Thread.currentThread().getName());
    }
}